home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
LDB171.ARJ
/
MSTR.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-12
|
2KB
|
143 lines
/*
mstr.cpp -- Loose Data Binder v 1.7:
mutually owned and persistent
"string form."
(C) Copyright 1992 John W. Small
All rights reserved
PSW / Power SoftWare
P.O. Box 10072
McLean, Virginia 22102 8072 USA
(703) 759-3838
This file was created by cloning fmutual.cpp
and
replacing: with:
CLASS Mstr
CPTR MstR
BASE Mutual
*/
#ifndef Mstr_HPP
#include "mstr.hpp"
#endif
#include <string.h>
int Mstr::initData(char *s, int dup)
{
this->s = ((dup && s)? strdup(s) : s);
if (this->s)
return 1; // success
return 0;
}
void Mstr::fput(ostream& os)
{
Mutual::fput(os);
int i = strlen(s);
os << i << Mendm;
if (i && os)
os.write(s,i);
if (!os)
error("unable to store Mstr "
"data on stream");
}
MutuaL Mstr::fget(istream& is, MutuaL InstancE)
{
int newed;
MstR thiS;
char * s;
int i;
is >> i >> Mnextm;
if (!is) {
serror("unable to load Mstr "
"data from stream",
ID_Mstr);
return MutuaL0;
}
if ((s = new char[i+i]) != (char *)0) {
if (i) {
is.read(s,i);
if (!is) {
delete s;
return MutuaL0;
}
}
s[i] = '\0';
}
if (InstancE) {
newed = 0;
thiS = (MstR) InstancE;
}
else {
if ((thiS = new Mstr(initVFTsEtc))
== MstR0) {
serror("unable to construct "
"new Mstr for "
"loading",
ID_Mstr);
return MutuaL0;
}
newed = 1;
InstancE = (MutuaL) thiS;
}
if (!Mutual::fget(is,InstancE)) {
if (newed)
delete (voiD) thiS;
return MutuaL0;
}
if (!thiS->initData(s,0)) {
serror("unable to initialize Mstr "
"from reloaded stream data",
ID_Mstr);
if (newed)
delete (voiD) thiS;
return MutuaL0;
}
return InstancE;
}
Mstr::Mstr (char *s)
: Mutual(initVFTsEtc)
{
(void) initData(s);
}
Mstr::Mstr(Mstr& c) : Mutual(c)
{
// copy initializer constructor
if (c.S())
s = strdup(c.S());
else
s = (char *) 0;
}
int Mstr::operator=(Mutual& m)
{
delete s;
s = (char *) 0;
if ((s = ((MstR)&m)->S()) != (char *)0)
s = strdup(s);
return 1; // enabled
}
MutuaL Mstr::clone()
{
// invokes copy initializer constructor
return (MutuaL) new Mstr(*this);
}
Mstr::~Mstr()
{
delete s;
}